package com.feeyo.monitor.service.imp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.feeyo.monitor.dao.InfluxDao;
import com.feeyo.monitor.service.VehicleTrackingService;


@Service
public class VehicleTrackingServiceImp implements VehicleTrackingService {

	@Autowired
	InfluxDao influxDao;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@Override
	public List getTrackingByVehicle(String devid, String startTime, String endTime) {
        List result = influxDao.getTrackingByVehicle(devid, startTime, endTime);
        if (result == null)
            return null;
        for(Object item : result){
            ArrayList itemc = (ArrayList)item;
            try {
                String datef = sdf2.format(org.apache.commons.lang3.time.DateUtils.addHours( sdf.parse((String)itemc.get(0)),8));
                itemc.set(0,datef);
                //System.out.println(itemc);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
		return result;
	}

    @Override
    public Boolean ifOnline(String devid) {
        return influxDao.ifOnline(devid);
    }

}
